import 'package:flutter/material.dart';
///
import 'package:fluro/fluro.dart';
/// router
import 'package:flutter_module_appaat/router/router_path.dart';

/// create by MZP 2019-08-12 20:27
///
/// 主要提供 context 使用的方法
///
///
class App {
  static Router router;

  static BuildContext context;

  static Future navigateTo(BuildContext context, String path,
      {Map<String, String> params, bool replace = false}) {
    if (params == null) {
      return App.router.navigateTo(context, getPath(path),
          transition: TransitionType.cupertino, replace: replace);
    } else {
      print("navigateTo:${getPath(path) + getNavigateToParams(params)}");
      return App.router.navigateTo(context, getPath(path) + getNavigateToParams(params),
          transition: TransitionType.cupertino, replace: replace);
    }
  }

  static void pop(BuildContext context) {
    App.router.pop(context);
  }

  static String getNavigateToParams(Map<String, String> params) {
    String path = "";
    var isFirst = true;
//    params.entries.toList().sublist(1, params.length).forEach((e) {
//
//    });
    params.entries.forEach((e) {
      var k = e.key;
      var v = e.value;
      if (isFirst) {
        path += "?$k=$v";
        isFirst = false;
      } else {
        path += "&$k=$v";
      }
    });
    return path;
  }
}
